﻿/**********************************************************
*
* 模块名称：Web层基类
* 当前版本：1.0
* 添加人员：楚涛
* 开始时间：2010-10-10
* 版本历史：v1.0
*
***********************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LXChuTao.ECG.Demo.WebUI
{
    /// <summary>
    /// BasePage 的摘要说明
    /// </summary>
    public class BasePage : System.Web.UI.Page
    {
        public BasePage()
        {
            this.Page.Theme = "Theme";
        }

        #region GridView排序辅助方法
        /// <summary>
        /// 升序标记
        /// </summary>
        protected bool IsAsc
        {
            get
            {
                if (ViewState["asc"] == null)
                {
                    ViewState["asc"] = false;
                }
                return Convert.ToBoolean(ViewState["asc"]);
            }
            set
            {
                ViewState["asc"] = value;
            }
        }
        /// <summary>
        /// 前次排序字段
        /// </summary>
        protected string PreSortExpression
        {
            get
            {
                if (ViewState["PreSortExpression"] == null)
                {
                    ViewState["PreSortExpression"] = string.Empty;
                }
                return ViewState["PreSortExpression"].ToString();
            }
            set
            {
                ViewState["PreSortExpression"] = value;
            }
        }
        /// <summary>
        /// 前次排序字符串
        /// </summary>
        protected string PreSort
        {
            get
            {
                if (ViewState["PreviousSort"] == null)
                {
                    ViewState["PreviousSort"] = string.Empty;
                }
                return ViewState["PreviousSort"].ToString();
            }
            set
            {
                ViewState["PreviousSort"] = value;
            }
        }
        /// <summary>
        /// 设置GridView排序标示
        /// </summary>
        /// <param name="gv">GridView</param>
        /// <param name="isAsc">升序标记</param>
        /// <param name="strSortExpression">排序字段</param>
        protected void SetDataViewSortColumn(GridView gv, bool isAsc, string strSortExpression)
        {
            int index = -1;
            char[] arrChr = new char[] { '↑', '↓' };
            if (gv != null && !string.IsNullOrEmpty(strSortExpression))
            {
                for (int i = 0; i < gv.Columns.Count; i++)
                {
                    gv.Columns[i].HeaderText = gv.Columns[i].HeaderText.TrimEnd(arrChr);
                    if (gv.Columns[i].SortExpression == strSortExpression)
                    {
                        index = i;
                    }
                }
                if (index != -1)
                {
                    if (isAsc)
                    {
                        gv.Columns[index].HeaderText += "↑";
                    }
                    else
                    {
                        gv.Columns[index].HeaderText += "↓";
                    }
                }
            }
        }
        #endregion
    }
}